package com.example.article.controller;

import com.example.article.service.ApAuthorService;
import com.usian.model.article.dtos.ApAuthorDto;
import com.usian.model.article.pojos.ApAuthor;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.common.enums.AppHttpCodeEnum;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "自媒体文章作者相关接口")
@RequestMapping("/api/v1/author")
public class ApAuthorController {
    @Autowired
    private ApAuthorService authorService;


    /**
     * 添加文章作者
     *
     */
    @PostMapping("/add_author")
    public ResponseResult addWeMediaUser(@RequestBody ApAuthorDto apAuthorDto) {
        Integer flag = authorService.addApAuthor(apAuthorDto);
        if (flag > 0) {
            return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
        }
        return ResponseResult.errorResult(AppHttpCodeEnum.FAIL);
    }

    /**
     * 根据名称查询作者
     *
     */
    @GetMapping("/get_author_by_name")
    public ResponseResult getAuthorByName(@RequestParam String name) {
        List<ApAuthor> wmUserList = authorService.getAuthorByName(name);
        return ResponseResult.okResult(wmUserList);
    }


}
